
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>IO流基础 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-sidebar-style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="集合.html" />
    
    
    <link rel="prev" href="../" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">基础篇</li>
        
        
    
        <li class="chapter active" data-level="2.1" data-path="IO流基础.html">
            
                <a href="IO流基础.html">
            
                    
                    IO流基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="集合.html">
            
                <a href="集合.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="异常处理.html">
            
                <a href="异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="线程.html">
            
                <a href="线程.html">
            
                    
                    线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="网络编程.html">
            
                <a href="网络编程.html">
            
                    
                    网络编程
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java进阶/MySQL.html">
            
                <a href="../java进阶/MySQL.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java进阶/Oracle.html">
            
                <a href="../java进阶/Oracle.html">
            
                    
                    Oracle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java进阶/Redis.html">
            
                <a href="../java进阶/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java进阶/Netty.html">
            
                <a href="../java进阶/Netty.html">
            
                    
                    Netty
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../java进阶/Spring.html">
            
                <a href="../java进阶/Spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../java进阶/SpringMVC.html">
            
                <a href="../java进阶/SpringMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../java进阶/单元测试.html">
            
                <a href="../java进阶/单元测试.html">
            
                    
                    SpringBoot单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../java进阶/设计模式.html">
            
                <a href="../java进阶/设计模式.html">
            
                    
                    二十三个设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.8.1" data-path="../java进阶/工厂模式.html">
            
                <a href="../java进阶/工厂模式.html">
            
                    
                    工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.2" data-path="../java进阶/单例模式.html">
            
                <a href="../java进阶/单例模式.html">
            
                    
                    单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.3" data-path="../java进阶/建造者模式.html">
            
                <a href="../java进阶/建造者模式.html">
            
                    
                    建造者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.4" data-path="../java进阶/原型模式.html">
            
                <a href="../java进阶/原型模式.html">
            
                    
                    原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.5" data-path="../java进阶/适配器模式.html">
            
                <a href="../java进阶/适配器模式.html">
            
                    
                    适配器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.6" data-path="../java进阶/责任链模式.html">
            
                <a href="../java进阶/责任链模式.html">
            
                    
                    责任链模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.7" data-path="../java进阶/桥接模式.html">
            
                <a href="../java进阶/桥接模式.html">
            
                    
                    桥接模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">高级篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../springcloud/1.cloud架构选型.html">
            
                <a href="../springcloud/1.cloud架构选型.html">
            
                    
                    Spring Cloud
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../springcloud/2.Provider-支付模块.html">
            
                <a href="../springcloud/2.Provider-支付模块.html">
            
                    
                    Provider-支付模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../springcloud/3.Consumer-订单模块.html">
            
                <a href="../springcloud/3.Consumer-订单模块.html">
            
                    
                    Consumer-订单模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../springcloud/4.重构-Common模块.html">
            
                <a href="../springcloud/4.重构-Common模块.html">
            
                    
                    重构-Common模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../springcloud/5.注册中心-Enreka.html">
            
                <a href="../springcloud/5.注册中心-Enreka.html">
            
                    
                    注册中心-Enreka
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../springcloud/6.负载均衡-@LoadBalance.html">
            
                <a href="../springcloud/6.负载均衡-@LoadBalance.html">
            
                    
                    负载均衡-@LoadBalance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../springcloud/7.更换注册中心-Zookeeper.html">
            
                <a href="../springcloud/7.更换注册中心-Zookeeper.html">
            
                    
                    更换注册中心-Zookeeper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../springcloud/8.更换注册中心-Consul.html">
            
                <a href="../springcloud/8.更换注册中心-Consul.html">
            
                    
                    更换注册中心-Consul
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../springcloud/9.负载均衡-Ribbon.html">
            
                <a href="../springcloud/9.负载均衡-Ribbon.html">
            
                    
                    负载均衡-Ribbon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.9" data-path="../springcloud/10.服务调用-OpenFeign.html">
            
                <a href="../springcloud/10.服务调用-OpenFeign.html">
            
                    
                    服务调用-OpenFeign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.10" data-path="../springcloud/11.熔断器-Hystrix.html">
            
                <a href="../springcloud/11.熔断器-Hystrix.html">
            
                    
                    熔断器-Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.11" data-path="../springcloud/12.网关-Gateway.html">
            
                <a href="../springcloud/12.网关-Gateway.html">
            
                    
                    网关-Gateway
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.12" data-path="../springcloud/13.配置中心-Config.html">
            
                <a href="../springcloud/13.配置中心-Config.html">
            
                    
                    配置中心-Config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.13" data-path="../springcloud/14.消息总线-bus.html">
            
                <a href="../springcloud/14.消息总线-bus.html">
            
                    
                    消息总线-Bus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.14" data-path="../springcloud/15.消息驱动-stream.html">
            
                <a href="../springcloud/15.消息驱动-stream.html">
            
                    
                    消息驱动-Stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.15" data-path="../springcloud/16.链路监控-Sleuth.html">
            
                <a href="../springcloud/16.链路监控-Sleuth.html">
            
                    
                    链路监控-Sleuth
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.16" data-path="../springcloud/17.注册中心&配置中心-nacos.html">
            
                <a href="../springcloud/17.注册中心&配置中心-nacos.html">
            
                    
                    注册中心&配置中心-nacos
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.17" data-path="../springcloud/18.限流-sentinel.html">
            
                <a href="../springcloud/18.限流-sentinel.html">
            
                    
                    限流-sentinel
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../java高级/JUC.html">
            
                <a href="../java高级/JUC.html">
            
                    
                    神秘的JUC包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../java高级/Docker.html">
            
                <a href="../java高级/Docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../java高级/布隆过滤器.html">
            
                <a href="../java高级/布隆过滤器.html">
            
                    
                    布隆过滤器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../java高级/Redission.html">
            
                <a href="../java高级/Redission.html">
            
                    
                    Redission
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../java高级/MQ.html">
            
                <a href="../java高级/MQ.html">
            
                    
                    消息队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="../java高级/JVM.html">
            
                <a href="../java高级/JVM.html">
            
                    
                    JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="../java书籍/《Effective Java》读书笔记.html">
            
                <a href="../java书籍/《Effective Java》读书笔记.html">
            
                    
                    《Effective Java》读书笔记 
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.8.1" data-path="../java书籍/创建和销毁对象.html">
            
                <a href="../java书籍/创建和销毁对象.html">
            
                    
                    创建和销毁对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">番外篇</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java面试/面试题.html">
            
                <a href="../java面试/面试题.html">
            
                    
                    面试题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../番外篇/小程序.html">
            
                <a href="../番外篇/小程序.html">
            
                    
                    微信小程序
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >IO流基础</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p><img src="https://tva1.sinaimg.cn/large/008eGmZEly1gou90mcp1nj30xp0dvab6.jpg" alt="&#x5B57;&#x7B26;&#x6D41;"></p>
<h3 id="&#x4E00;&#x3001;&#x5B57;&#x7B26;&#x6D41;"><a name="&#x4E00;&#x3001;&#x5B57;&#x7B26;&#x6D41;" class="plugin-anchor" href="#&#x4E00;&#x3001;&#x5B57;&#x7B26;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E00;&#x3001;&#x5B57;&#x7B26;&#x6D41;</h3>
<ol>
<li><h4 id="filereader"><a name="filereader" class="plugin-anchor" href="#filereader"><i class="fa fa-link" aria-hidden="true"></i></a>FileReader</h4>
<pre><code class="lang-JAVA"><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">read</span><span class="hljs-params">()</span></span>; <span class="hljs-comment">//&#x8BFB;&#x53D6;&#x5355;&#x4E2A;&#x5B57;&#x7B26;&#x5E76;&#x8FD4;&#x56DE;</span>
<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">read</span><span class="hljs-params">(<span class="hljs-keyword">char</span>[] cbuf)</span></span>;<span class="hljs-comment">// &#x4E00;&#x6B21;&#x8BFB;&#x53D6;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x6570;&#x7EC4;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x5B9E;&#x9645;&#x8BFB;&#x53D6;&#x7684;&#x5B57;&#x7B26;&#x4E2A;&#x6570;</span>
</code></pre>
</li>
<li><h4 id="filewriter"><a name="filewriter" class="plugin-anchor" href="#filewriter"><i class="fa fa-link" aria-hidden="true"></i></a>FileWriter</h4>
<pre><code class="lang-java"><span class="hljs-comment">//&#x5199;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x6570;&#x636E;</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(String str)</span></span>;

<span class="hljs-comment">//&#x5199;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x6570;&#x636E;, index:&#x5F00;&#x59CB;&#x7D22;&#x5F15;,len:&#x5199;&#x51E0;&#x4E2A;</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(String str,<span class="hljs-keyword">int</span> index,<span class="hljs-keyword">int</span> len)</span></span>;

<span class="hljs-comment">//&#x5199;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x6570;&#x636E;,&#x8FD9;&#x91CC;&#x5199;int&#x7C7B;&#x578B;&#x7684;&#x597D;&#x5904;&#x662F;&#x65E2;&#x53EF;&#x4EE5;&#x5199;char&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5199;char&#x5BF9;&#x5E94;&#x7684;int&#x7C7B;&#x578B;&#x7684;&#x503C;&#x3002;&#x5982;&#xFF1A;&apos;a&apos;,97</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(<span class="hljs-keyword">int</span> ch)</span></span>;

<span class="hljs-comment">//&#x5199;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x6570;&#x7EC4;&#x6570;&#x636E;</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(<span class="hljs-keyword">char</span>[] chs)</span></span>;

<span class="hljs-comment">//&#x5199;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x6570;&#x7EC4;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x6570;&#x636E;, index:&#x5F00;&#x59CB;&#x7D22;&#x5F15;,len:&#x5199;&#x51E0;&#x4E2A;</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(<span class="hljs-keyword">char</span>[] chs,<span class="hljs-keyword">int</span> index,<span class="hljs-keyword">int</span> len)</span></span>;
</code></pre>
</li>
<li><h4 id="bufferreader"><a name="bufferreader" class="plugin-anchor" href="#bufferreader"><i class="fa fa-link" aria-hidden="true"></i></a>BufferReader</h4>
<pre><code class="lang-java"><span class="hljs-function">String <span class="hljs-title">readLine</span><span class="hljs-params">()</span></span>;<span class="hljs-comment">//&#x4E00;&#x6B21;&#x8BFB;&#x53D6;&#x4E00;&#x884C;&#x6570;&#x636E;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x8BFB;&#x53D6;&#x6362;&#x884C;&#x7B26;</span>
</code></pre>
</li>
<li><h4 id="bufferwriter"><a name="bufferwriter" class="plugin-anchor" href="#bufferwriter"><i class="fa fa-link" aria-hidden="true"></i></a>BufferWriter</h4>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">newLine</span><span class="hljs-params">()</span></span>;<span class="hljs-comment">//&#x5199;&#x4E00;&#x4E2A;&#x6362;&#x884C;&#x7B26;&#xFF0C;&#x8FD9;&#x4E2A;&#x6362;&#x884C;&#x7B26;&#x7531;&#x7CFB;&#x7EDF;&#x51B3;&#x5B9A;</span>
</code></pre>
</li>
<li><h4 id="&#x6CE8;&#x610F;"><a name="&#x6CE8;&#x610F;" class="plugin-anchor" href="#&#x6CE8;&#x610F;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6CE8;&#x610F;</h4>
<p>&#x5B57;&#x7B26;&#x6D41;&#x4E0D;&#x5237;&#x65B0;&#x662F;&#x5199;&#x4E0D;&#x5230;&#x6587;&#x4EF6;&#x7684;&#x3002;</p>
</li>
</ol>
<h3 id="&#x4E8C;&#x3001;&#x8F6C;&#x6362;&#x6D41;"><a name="&#x4E8C;&#x3001;&#x8F6C;&#x6362;&#x6D41;" class="plugin-anchor" href="#&#x4E8C;&#x3001;&#x8F6C;&#x6362;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E8C;&#x3001;&#x8F6C;&#x6362;&#x6D41;</h3>
<ol>
<li><h4 id="outputstreamwriter-&#x5C06;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x51FA;&#x6D41;"><a name="outputstreamwriter-&#x5C06;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x51FA;&#x6D41;" class="plugin-anchor" href="#outputstreamwriter-&#x5C06;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x51FA;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>OutputStreamWriter &#x5C06;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x51FA;&#x6D41;</h4>
<ul>
<li><p><strong>&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF1A;</strong></p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">OutputStreamWriter</span><span class="hljs-params">(OutputStream out)</span></span>; <span class="hljs-comment">//&#x5C06;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x8282;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x6D41;</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">OutputStreamWriter</span><span class="hljs-params">(OutputStream out, String charsetName)</span></span>;
</code></pre>
</li>
<li><p><strong>&#x8F6C;&#x5316;&#x6D41;&#x7684;&#x4F5C;&#x7528;&#xFF1A;</strong></p>
<ul>
<li>&#x7528;&#x4E8E;&#x65B9;&#x6CD5;&#x7684;&#x8C03;&#x7528;,&#x5F62;&#x53C2;&#x662F;&#x5B57;&#x7B26;&#x6D41;&#xFF0C;&#x4F46;&#x662F;&#x5F53;&#x4F60;&#x7684;&#x9009;&#x62E9;&#x53EA;&#x6709;&#x5B57;&#x8282;&#x6D41;&#x65F6;&#xFF0C;&#x7528;&#x8BE5;&#x65B9;&#x6CD5;&#x5219;&#x5B9E;&#x73B0;&#x8F6C;&#x6362;</li>
<li>&#x7528;&#x4E8E;&#x89E3;&#x51B3;&#x6587;&#x4EF6;&#x7684;&#x7F16;&#x7801;&#x95EE;&#x9898;</li>
</ul>
</li>
</ul>
</li>
<li><h4 id="inputstreamreader-&#x5C06;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x5165;&#x6D41;"><a name="inputstreamreader-&#x5C06;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x5165;&#x6D41;" class="plugin-anchor" href="#inputstreamreader-&#x5C06;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x5165;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>InputStreamReader &#x5C06;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x8F6C;&#x4E3A;&#x5B57;&#x7B26;&#x8F93;&#x5165;&#x6D41;</h4>
<ul>
<li><p><strong>&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF1A;</strong></p>
<pre><code>public InputStreamReader(InputStream in);
public InputStreamReader(InputStream in&#xFF0C; String  charset); 
//&#x5199;&#x7684;&#x65F6;&#x5019;&#x4F7F;&#x7528;&#x4EC0;&#x4E48;&#x7F16;&#x7801;&#xFF0C;&#x8BFB;&#x53D6;&#x7684;&#x65F6;&#x5019;&#x4E5F;&#x7528;&#x4EC0;&#x4E48;&#x7F16;&#x7801;&#xFF0C;&#x5426;&#x5219;&#x4F1A;&#x53D1;&#x751F;&#x9519;&#x8BEF;&#x3002;
</code></pre></li>
</ul>
</li>
</ol>
<p><br></p>
<p><img src="https://tva1.sinaimg.cn/large/008eGmZEly1gou98dfas4j30xp0bmq42.jpg" alt="&#x5B57;&#x8282;&#x6D41;"></p>
<h3 id="&#x4E09;&#x3001;&#x5B57;&#x8282;&#x6D41;"><a name="&#x4E09;&#x3001;&#x5B57;&#x8282;&#x6D41;" class="plugin-anchor" href="#&#x4E09;&#x3001;&#x5B57;&#x8282;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E09;&#x3001;&#x5B57;&#x8282;&#x6D41;</h3>
<ol>
<li><h4 id="outputstream-&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;"><a name="outputstream-&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;" class="plugin-anchor" href="#outputstream-&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>OutputStream &#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;</h4>
<p>OutputStream&#x7C7B;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x662F;&#x5B57;&#x8282;&#x6D41;&#x8F93;&#x51FA;&#x7684;&#x8D85;&#x7C7B;&#x3002;&#x5B9E;&#x73B0;&#x7C7B;&#x5982;&#xFF1A;<strong>FileOutputStream</strong></p>
<ul>
<li><p><strong>&#x6784;&#x9020;&#x65B9;&#x6CD5;</strong></p>
<pre><code class="lang-java">FileOutputStream(File file,<span class="hljs-keyword">boolean</span> append); <span class="hljs-comment">//&#x662F;&#x5426;&#x8FFD;&#x52A0;</span>
FileOutputStream(String name,<span class="hljs-keyword">boolean</span> append); <span class="hljs-comment">//&#x662F;&#x5426;&#x8FFD;&#x52A0;</span>
</code></pre>
</li>
<li><p><strong>&#x666E;&#x901A;&#x65B9;&#x6CD5;</strong></p>
<pre><code class="lang-java">   <span class="hljs-comment">//&#x5199;&#x51FA;&#x6574;&#x4E2A;&#x5B57;&#x8282;&#x6570;&#x7EC4;&#x3002;</span>
   <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(<span class="hljs-keyword">byte</span>[] b)</span></span>;

   <span class="hljs-comment">//&#x5199;&#x51FA;&#x5B57;&#x8282;&#x6570;&#x7EC4;&#x7684;&#x4E00;&#x90E8;&#x5206;</span>
   <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(<span class="hljs-keyword">byte</span>[] b,<span class="hljs-keyword">int</span> off,<span class="hljs-keyword">int</span> len)</span></span>;

   <span class="hljs-comment">//&#x5199;&#x51FA;&#x6307;&#x5B9A;&#x5B57;&#x8282;</span>
   <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">write</span><span class="hljs-params">(<span class="hljs-keyword">int</span> b)</span></span>;
</code></pre>
</li>
<li><p><strong>&#x4F8B;&#x5B50;</strong></p>
<pre><code class="lang-java">   <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> Exception </span>{
       File file = <span class="hljs-keyword">new</span> File(<span class="hljs-string">&quot;c:\\file.txt&quot;</span>);
       FileOutputStream fos = <span class="hljs-keyword">new</span> FileOutputStream(file, <span class="hljs-keyword">true</span>);
       String str = <span class="hljs-string">&quot;\r\n&quot;</span>+<span class="hljs-string">&quot;itcast&quot;</span>;
       fos.write(str.getBytes());
       fos.close();
   }
</code></pre>
</li>
</ul>
</li>
<li><h4 id="inputstream-&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x3002;"><a name="inputstream-&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x3002;" class="plugin-anchor" href="#inputstream-&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>InputStream &#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x3002;</h4>
<p>InputStream&#x7C7B;&#x662F;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x662F;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x7684;&#x8D85;&#x7C7B;&#x3002;&#x5B9E;&#x73B0;&#x7C7B;&#x5982;&#xFF1A;<strong>FileInputStream</strong></p>
<ul>
<li><p><strong>&#x6784;&#x9020;&#x65B9;&#x6CD5;</strong></p>
<pre><code class="lang-java">FileInputStream(File file);

FileInputStream(String name);
</code></pre>
</li>
<li><p><strong>&#x666E;&#x901A;&#x65B9;&#x6CD5;</strong></p>
<pre><code class="lang-java"><span class="hljs-comment">// &#x8BFB;&#x53D6;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x3002;</span>
read();

<span class="hljs-comment">// &#x8BFB;&#x53D6;&#x5B57;&#x8282;&#x6570;&#x7EC4;&#x3002;</span>
read(<span class="hljs-keyword">byte</span>[] b);
</code></pre>
</li>
<li><p><strong>&#x4F8B;&#x5B50;</strong></p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException </span>{

    File file = <span class="hljs-keyword">new</span> File(<span class="hljs-string">&quot;c:\\file.txt&quot;</span>);
    <span class="hljs-comment">// &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x6D41;&#x5BF9;&#x8C61;,&#x5FC5;&#x987B;&#x660E;&#x786E;&#x6570;&#x636E;&#x6E90;&#xFF0C;&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x521B;&#x5EFA;&#x5B57;&#x8282;&#x8BFB;&#x53D6;&#x6D41;&#x548C;&#x6570;&#x636E;&#x6E90;&#x76F8;&#x5173;&#x8054;&#x3002;</span>
    FileInputStream fis = <span class="hljs-keyword">new</span> FileInputStream(file);
    <span class="hljs-comment">//&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x6570;&#x7EC4;&#x3002;</span>
    <span class="hljs-keyword">byte</span>[] buf = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">1024</span>];<span class="hljs-comment">//&#x957F;&#x5EA6;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x6210;1024&#x7684;&#x6574;&#x6570;&#x500D;&#x3002;</span>
    <span class="hljs-keyword">int</span> len = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">while</span>((len=fis.read(buf))!=-<span class="hljs-number">1</span>){
        System.out.println(<span class="hljs-keyword">new</span> String(buf,<span class="hljs-number">0</span>,len));
    }
    fis.close();
}
</code></pre>
</li>
</ul>
</li>
</ol>
<h3 id="&#x56DB;&#x3001;&#x7EC4;&#x5408;&#x4F7F;&#x7528;&#x8F93;&#x5165;&#x8F93;&#x51FA;"><a name="&#x56DB;&#x3001;&#x7EC4;&#x5408;&#x4F7F;&#x7528;&#x8F93;&#x5165;&#x8F93;&#x51FA;" class="plugin-anchor" href="#&#x56DB;&#x3001;&#x7EC4;&#x5408;&#x4F7F;&#x7528;&#x8F93;&#x5165;&#x8F93;&#x51FA;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x56DB;&#x3001;&#x7EC4;&#x5408;&#x4F7F;&#x7528;&#x8F93;&#x5165;&#x8F93;&#x51FA;</h3>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException </span>{
    File srcFile = <span class="hljs-keyword">new</span> File(<span class="hljs-string">&quot;c:\\YesDir\test.JPG&quot;</span>);
    File destFile = <span class="hljs-keyword">new</span> File(<span class="hljs-string">&quot;copyTest.JPG&quot;</span>);

    <span class="hljs-comment">// &#x660E;&#x786E;&#x5B57;&#x8282;&#x6D41; &#x8F93;&#x5165;&#x6D41;&#x548C;&#x6E90;&#x76F8;&#x5173;&#x8054;&#xFF0C;&#x8F93;&#x51FA;&#x6D41;&#x548C;&#x76EE;&#x7684;&#x5173;&#x8054;&#x3002;</span>
    FileInputStream fis = <span class="hljs-keyword">new</span> FileInputStream(srcFile);
    FileOutputStream fos = <span class="hljs-keyword">new</span> FileOutputStream(destFile);

      <span class="hljs-comment">//&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7F13;&#x51B2;&#x533A;&#x3002;</span>
    <span class="hljs-keyword">byte</span>[] buf = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">1024</span>];
    <span class="hljs-keyword">int</span> len = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">while</span> ((len = fis.read(buf)) != -<span class="hljs-number">1</span>) {
        fos.write(buf, <span class="hljs-number">0</span>, len);<span class="hljs-comment">// &#x5C06;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6307;&#x5B9A;&#x957F;&#x5EA6;&#x7684;&#x6570;&#x636E;&#x5199;&#x5165;&#x5230;&#x8F93;&#x51FA;&#x6D41;&#x4E2D;&#x3002;</span>
    }

      <span class="hljs-comment">// &#x5173;&#x95ED;&#x8D44;&#x6E90;&#x3002;</span>
    fos.close();
    fis.close();
}
</code></pre>
<h3 id="&#x4E94;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x7F13;&#x51B2;&#x6D41;"><a name="&#x4E94;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x7F13;&#x51B2;&#x6D41;" class="plugin-anchor" href="#&#x4E94;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x7F13;&#x51B2;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E94;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x7F13;&#x51B2;&#x6D41;</h3>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span>  <span class="hljs-title">write</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> IOException </span>{

    <span class="hljs-comment">//&#x521B;&#x5EFA;&#x57FA;&#x672C;&#x7684;&#x5B57;&#x8282;&#x8F93;&#x51FA;&#x6D41;</span>
    FileOutputStream fileOut =  <span class="hljs-keyword">new</span> FileOutputStream(<span class="hljs-string">&quot;abc.txt&quot;</span>);
    <span class="hljs-comment">//&#x4F7F;&#x7528;&#x9AD8;&#x6548;&#x7684;&#x6D41;&#xFF0C;&#x628A;&#x57FA;&#x672C;&#x7684;&#x6D41;&#x8FDB;&#x884C;&#x5C01;&#x88C5;&#xFF0C;&#x5B9E;&#x73B0;&#x901F;&#x5EA6;&#x7684;&#x63D0;&#x5347;</span>
    BufferedOutputStream out = <span class="hljs-keyword">new</span> BufferedOutputStream(fileOut);
    <span class="hljs-comment">//&#x5199;&#x6570;&#x636E;</span>
    out.write(<span class="hljs-string">&quot;hello&quot;</span>.getBytes());
    <span class="hljs-comment">//&#x5173;&#x95ED;&#x6D41;</span>
    out.close();

}
</code></pre>
<h3 id="&#x516D;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x7F13;&#x51B2;&#x6D41;"><a name="&#x516D;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x7F13;&#x51B2;&#x6D41;" class="plugin-anchor" href="#&#x516D;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x7F13;&#x51B2;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x516D;&#x3001;&#x5B57;&#x8282;&#x8F93;&#x5165;&#x7F13;&#x51B2;&#x6D41;</h3>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span>  <span class="hljs-title">read</span><span class="hljs-params">()</span>  <span class="hljs-keyword">throws</span>  IOException </span>{
    <span class="hljs-comment">//1,&#x521B;&#x5EFA;&#x7F13;&#x51B2;&#x6D41;&#x5BF9;&#x8C61;</span>
    FileInputStream fileIn =  <span class="hljs-keyword">new</span>  FileInputStream(<span class="hljs-string">&quot;abc.txt&quot;</span>);
    <span class="hljs-comment">//&#x628A;&#x57FA;&#x672C;&#x7684;&#x6D41;&#x5305;&#x88C5;&#x6210;&#x9AD8;&#x6548;&#x7684;&#x6D41;</span>
    BufferedInputStream in =  <span class="hljs-keyword">new</span>  BufferedInputStream(fileIn);
    <span class="hljs-comment">//2&#xFF0C;&#x8BFB;&#x6570;&#x636E;</span>
    <span class="hljs-keyword">int</span> ch = -<span class="hljs-number">1</span>;
    <span class="hljs-keyword">while</span>  ( (ch = in.read()) != -<span class="hljs-number">1</span> ) {
      <span class="hljs-comment">//&#x6253;&#x5370;</span>
      System.out.print((<span class="hljs-keyword">char</span>)ch);
    }
    <span class="hljs-comment">//3&#xFF0C;&#x5173;&#x95ED;</span>
    in.close();
}
</code></pre>
<h3 id="&#x4E03;&#x3001;&#x6848;&#x4F8B;-&#x590D;&#x5236;&#x5355;&#x7EA7;&#x6587;&#x4EF6;&#x5939;"><a name="&#x4E03;&#x3001;&#x6848;&#x4F8B;-&#x590D;&#x5236;&#x5355;&#x7EA7;&#x6587;&#x4EF6;&#x5939;" class="plugin-anchor" href="#&#x4E03;&#x3001;&#x6848;&#x4F8B;-&#x590D;&#x5236;&#x5355;&#x7EA7;&#x6587;&#x4EF6;&#x5939;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E03;&#x3001;&#x6848;&#x4F8B; &#x590D;&#x5236;&#x5355;&#x7EA7;&#x6587;&#x4EF6;&#x5939;</h3>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span>  <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span>  <span class="hljs-keyword">throws</span> IOException </span>{

    <span class="hljs-comment">// &#x5C01;&#x88C5;&#x76EE;&#x5F55;</span>
    File srcFolder =  <span class="hljs-keyword">new</span>  File(<span class="hljs-string">&quot;e:\\demo&quot;</span>);
    <span class="hljs-comment">// &#x5C01;&#x88C5;&#x76EE;&#x7684;&#x5730;</span>
    File destFolder =  <span class="hljs-keyword">new</span>  File(<span class="hljs-string">&quot;e:\\test&quot;</span>);
    <span class="hljs-comment">// &#x5982;&#x679C;&#x76EE;&#x7684;&#x5730;&#x6587;&#x4EF6;&#x5939;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5C31;&#x521B;&#x5EFA;</span>
    <span class="hljs-keyword">if</span> (!destFolder.exists()) {
        destFolder.mkdir();
    }

    <span class="hljs-comment">// &#x83B7;&#x53D6;&#x8BE5;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x6587;&#x672C;&#x7684;File&#x6570;&#x7EC4;</span>
    File[] fileArray = srcFolder.listFiles();
    <span class="hljs-comment">// &#x904D;&#x5386;&#x8BE5;File&#x6570;&#x7EC4;&#xFF0C;&#x5F97;&#x5230;&#x6BCF;&#x4E00;&#x4E2A;File&#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">for</span> (File file : fileArray) {
      <span class="hljs-comment">// System.out.println(file);</span>
      <span class="hljs-comment">// &#x6570;&#x636E;&#x6E90;&#xFF1A;e:\\demo\\e.mp3</span>
      <span class="hljs-comment">// &#x76EE;&#x7684;&#x5730;&#xFF1A;e:\\test\\e.mp3</span>
      String name = file.getName(); <span class="hljs-comment">// e.mp3</span>
      File newFile =  <span class="hljs-keyword">new</span>  File(destFolder, name); <span class="hljs-comment">// e:\\test\\e.mp3</span>
      copyFile(file, newFile);
    }

}

<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span>  <span class="hljs-title">copyFile</span><span class="hljs-params">(File file, File newFile)</span>  <span class="hljs-keyword">throws</span>  IOException </span>{
    BufferedInputStream bis =  <span class="hljs-keyword">new</span>  BufferedInputStream(<span class="hljs-keyword">new</span>  FileInputStream(file));
    BufferedOutputStream bos =  <span class="hljs-keyword">new</span>  BufferedOutputStream(<span class="hljs-keyword">new</span>  FileOutputStream(newFile));

    <span class="hljs-keyword">byte</span> [] bys =  <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span> [<span class="hljs-number">1024</span>];
    <span class="hljs-keyword">int</span>  len = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">while</span>  ((len = bis.read(bys)) != -<span class="hljs-number">1</span>) {
        bos.write(bys, <span class="hljs-number">0</span>, len);
    }

    bos.close();
    bis.close();
}
</code></pre>
<h3 id="&#x516B;&#x3001;&#x5BF9;&#x8C61;&#x5E8F;&#x5217;&#x5316;&#x6D41;-objectoutputstream"><a name="&#x516B;&#x3001;&#x5BF9;&#x8C61;&#x5E8F;&#x5217;&#x5316;&#x6D41;-objectoutputstream" class="plugin-anchor" href="#&#x516B;&#x3001;&#x5BF9;&#x8C61;&#x5E8F;&#x5217;&#x5316;&#x6D41;-objectoutputstream"><i class="fa fa-link" aria-hidden="true"></i></a>&#x516B;&#x3001;&#x5BF9;&#x8C61;&#x5E8F;&#x5217;&#x5316;&#x6D41; ObjectOutputStream</h3>
<ol>
<li><p><strong>&#x6784;&#x9020;&#x65B9;&#x6CD5;</strong></p>
<pre><code>ObjectOutputStream(OutputStream out);
</code></pre></li>
<li><p><strong>&#x666E;&#x901A;&#x65B9;&#x6CD5;</strong></p>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span>  <span class="hljs-title">writeObject</span><span class="hljs-params">(Object obj )</span></span>;
<span class="hljs-comment">//&#x5C06;&#x6307;&#x5B9A;&#x5BF9;&#x8C61;&#x5199;&#x5165;&#x6D41;&#x3002;</span>
</code></pre>
</li>
<li><p><strong>&#x4F8B;&#x5B50;</strong></p>
<pre><code class="lang-java"><span class="hljs-comment">//&#x660E;&#x786E;&#x5B58;&#x50A8;&#x5BF9;&#x8C61;&#x7684;&#x6587;&#x4EF6;&#x3002;</span>
FileOutputStream fos = <span class="hljs-keyword">new</span> FileOutputStream(<span class="hljs-string">&quot;tempfile\\obj.object&quot;</span>);

<span class="hljs-comment">//&#x7ED9;&#x64CD;&#x4F5C;&#x6587;&#x4EF6;&#x5BF9;&#x8C61;&#x52A0;&#x5165;&#x5199;&#x5165;&#x5BF9;&#x8C61;&#x529F;&#x80FD;&#x3002;</span>
ObjectOutputStream oos = <span class="hljs-keyword">new</span> ObjectOutputStream(fos);

<span class="hljs-comment">//&#x8C03;&#x7528;&#x4E86;&#x5199;&#x5165;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;&#x3002;</span>
oos.writeObject(<span class="hljs-keyword">new</span> Person(<span class="hljs-string">&quot;wangcai&quot;</span>,<span class="hljs-number">20</span>));

<span class="hljs-comment">//&#x5173;&#x95ED;&#x8D44;&#x6E90;&#x3002;</span>
oos.close();
</code></pre>
</li>
</ol>
<h3 id="&#x4E5D;&#x3001;&#x5BF9;&#x8C61;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x6D41;-objectinputstream"><a name="&#x4E5D;&#x3001;&#x5BF9;&#x8C61;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x6D41;-objectinputstream" class="plugin-anchor" href="#&#x4E5D;&#x3001;&#x5BF9;&#x8C61;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x6D41;-objectinputstream"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E5D;&#x3001;&#x5BF9;&#x8C61;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x6D41; ObjectInputStream</h3>
<ol>
<li><p><strong>&#x6784;&#x9020;&#x65B9;&#x6CD5;</strong>&#x3002;</p>
<pre><code>ObjectInputStream ( InputStream in) ;
</code></pre></li>
<li><p><strong>&#x666E;&#x901A;&#x65B9;&#x6CD5;</strong>&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-function">Object <span class="hljs-title">readObject</span><span class="hljs-params">()</span></span>;
<span class="hljs-comment">//&#x4ECE;&#x6D41;&#x4E0A;&#x8BFB;&#x53D6;&#x5BF9;&#x8C61;&#x5230;&#x5185;&#x5B58;&#x3002;</span>
</code></pre>
</li>
<li><p><strong>&#x4F8B;&#x5B50;</strong></p>
<pre><code class="lang-java"><span class="hljs-comment">//1,&#x5B9A;&#x4E49;&#x6D41;&#x5BF9;&#x8C61;&#x5173;&#x8054;&#x5B58;&#x50A8;&#x4E86;&#x5BF9;&#x8C61;&#x6587;&#x4EF6;&#x3002;</span>
FileInputStream fis = <span class="hljs-keyword">new</span> FileInputStream(<span class="hljs-string">&quot;tempfile\\obj.object&quot;</span>);

<span class="hljs-comment">//2,&#x5EFA;&#x7ACB;&#x7528;&#x4E8E;&#x8BFB;&#x53D6;&#x5BF9;&#x8C61;&#x7684;&#x529F;&#x80FD;&#x5BF9;&#x8C61;&#x3002;</span>
ObjectInputStream ois = <span class="hljs-keyword">new</span> ObjectInputStream(fis);
Person obj = (Person)ois.readObject();
System.out.println(obj.toString());
</code></pre>
</li>
</ol>
<h3 id="&#x5341;&#x3001;&#x5E8F;&#x5217;&#x5316;&#x63A5;&#x53E3;"><a name="&#x5341;&#x3001;&#x5E8F;&#x5217;&#x5316;&#x63A5;&#x53E3;" class="plugin-anchor" href="#&#x5341;&#x3001;&#x5E8F;&#x5217;&#x5316;&#x63A5;&#x53E3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5341;&#x3001;&#x5E8F;&#x5217;&#x5316;&#x63A5;&#x53E3;</h3>
<p>&#x200B;    &#x5F53;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x8981;&#x80FD;&#x88AB;&#x5E8F;&#x5217;&#x5316;&#xFF0C;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x6240;&#x5C5E;&#x7684;&#x7C7B;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;Serializable&#x63A5;&#x53E3;&#x3002;&#x5426;&#x5219;&#x4F1A;&#x53D1;&#x751F;NotSerializableException&#x5F02;&#x5E38;&#x3002;&#x540C;&#x65F6;&#x5F53;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x5BF9;&#x8C61;&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x5BF9;&#x8C61;&#x6240;&#x5C5E;&#x7684;class&#x6587;&#x4EF6;&#x5728;&#x5E8F;&#x5217;&#x5316;&#x4E4B;&#x540E;&#x8FDB;&#x884C;&#x7684;&#x4FEE;&#x6539;&#xFF0C;&#x90A3;&#x4E48;&#x8FDB;&#x884C;&#x53CD;&#x5E8F;&#x5217;&#x5316;&#x4E5F;&#x4F1A;&#x53D1;&#x751F;&#x5F02;&#x5E38;InvalidClassException&#x3002;</p>
<h3 id="&#x5341;&#x4E00;&#x3001;&#x77AC;&#x6001;&#x5173;&#x952E;&#x5B57;-transient"><a name="&#x5341;&#x4E00;&#x3001;&#x77AC;&#x6001;&#x5173;&#x952E;&#x5B57;-transient" class="plugin-anchor" href="#&#x5341;&#x4E00;&#x3001;&#x77AC;&#x6001;&#x5173;&#x952E;&#x5B57;-transient"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5341;&#x4E00;&#x3001;&#x77AC;&#x6001;&#x5173;&#x952E;&#x5B57; transient</h3>
<p>&#x200B;    &#x67D0;&#x4E2A;&#x7C7B;&#x7684;&#x5C5E;&#x6027; &#x4E0D;&#x9700;&#x8981;&#x88AB;&#x5E8F;&#x5217;&#x5316;&#x65F6; &#xFF0C; &#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x7528;&#x5173;&#x952E;&#x5B57; transient &#x4FEE;&#x9970;&#xFF0C;&#x540C;&#x65F6;&#x9759;&#x6001;&#x4FEE;&#x9970;&#x7684;&#x5C5E;&#x6027;&#x4E5F;&#x4E0D;&#x4F1A;&#x88AB;&#x5E8F;&#x5217;&#x5316;&#x3002;&#x56E0;&#x4E3A;&#x5E8F;&#x5217;&#x5316;&#x628A;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x6301;&#x4E45;&#x5316;&#xFF0C;&#x800C;&#x9759;&#x6001;&#x7684;&#x5C5E;&#x6027;&#x5C5E;&#x4E8E;&#x7C7B;&#x52A0;&#x8F7D;&#x65F6;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x4F1A;&#x88AB;&#x5E8F;&#x5217;&#x5316;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> String name;
<span class="hljs-keyword">private</span> <span class="hljs-keyword">transient</span> <span class="hljs-keyword">int</span> age;
</code></pre>
<h3 id="&#x5341;&#x4E8C;&#x3001;&#x6253;&#x5370;&#x6D41;"><a name="&#x5341;&#x4E8C;&#x3001;&#x6253;&#x5370;&#x6D41;" class="plugin-anchor" href="#&#x5341;&#x4E8C;&#x3001;&#x6253;&#x5370;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5341;&#x4E8C;&#x3001;&#x6253;&#x5370;&#x6D41;</h3>
<ol>
<li><h4 id="&#x5B57;&#x8282;&#x6253;&#x5370;&#x6D41;--printstream"><a name="&#x5B57;&#x8282;&#x6253;&#x5370;&#x6D41;--printstream" class="plugin-anchor" href="#&#x5B57;&#x8282;&#x6253;&#x5370;&#x6D41;--printstream"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B57;&#x8282;&#x6253;&#x5370;&#x6D41;  PrintStream.</h4>
</li>
<li><h4 id="&#x5B57;&#x7B26;&#x6253;&#x5370;&#x6D41;--printwriter"><a name="&#x5B57;&#x7B26;&#x6253;&#x5370;&#x6D41;--printwriter" class="plugin-anchor" href="#&#x5B57;&#x7B26;&#x6253;&#x5370;&#x6D41;--printwriter"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B57;&#x7B26;&#x6253;&#x5370;&#x6D41;  PrintWriter.</h4>
</li>
<li><h4 id="&#x65B9;&#x6CD5;"><a name="&#x65B9;&#x6CD5;" class="plugin-anchor" href="#&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x65B9;&#x6CD5;</h4>
<pre><code class="lang-java"><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">print</span><span class="hljs-params">(String str)</span></span>;
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">println</span><span class="hljs-params">(Sting str)</span></span>;
</code></pre>
</li>
<li><h4 id="&#x4F8B;&#x5B50;"><a name="&#x4F8B;&#x5B50;" class="plugin-anchor" href="#&#x4F8B;&#x5B50;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4F8B;&#x5B50;</h4>
<pre><code class="lang-java"><span class="hljs-comment">//&#x521B;&#x5EFA;&#x6D41;</span>
<span class="hljs-comment">//PrintWriter out = new PrintWriter(new FileWriter(&quot;printFile.txt&quot;));</span>
PrintWriter out = <span class="hljs-keyword">new</span> PrintWriter(<span class="hljs-string">&quot;printFile.txt&quot;</span>);

<span class="hljs-comment">//&#x5199;&#x6570;&#x636E;</span>
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">int</span> i=<span class="hljs-number">0</span>; i&lt;<span class="hljs-number">5</span>; i++) {
    out.println(<span class="hljs-string">&quot;helloWorld&quot;</span>);
}

<span class="hljs-comment">//&#x5173;&#x95ED;&#x6D41;</span>
out.close();
</code></pre>
</li>
</ol>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; mine 2022-2025 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2022-06-23 10:56:48
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../" class="navigation navigation-prev " aria-label="Previous page: 前言">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="集合.html" class="navigation navigation-next " aria-label="Next page: 集合">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"IO流基础","level":"2.1","depth":1,"next":{"title":"集合","level":"2.2","depth":1,"path":"java基础/集合.md","ref":"java基础/集合.md","articles":[]},"previous":{"title":"前言","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["back-to-top-button","code","splitter","expandable-chapters-small","anchors","theme-comscore","tbfed-pagefooter","sidebar-style","pageview-count","popup"],"pluginsConfig":{"sidebar-style":{"author":"梁兴龙","title":"《Java 笔记本》"},"tbfed-pagefooter":{"copyright":"Copyright &copy mine 2022-2025","modify_label":"文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"pageview-count":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"java基础/IO流基础.md","mtime":"2022-06-23T02:56:48.176Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-08-22T03:22:22.085Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sidebar-style/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

